package cn.com.scan.jsonparser;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.List;

import cn.com.scan.entity.ApplicationItem;
import cn.com.scan.entity.Check;
import cn.com.scan.entity.ExportItem;
import cn.com.scan.entity.ImportItem;
import cn.com.scan.entity.Storage;
import cn.com.scan.entity.UseCheck;
import cn.com.scan.entity.User;

public class ParseJson {
    private static Gson gson;
    static {
        if(null == gson){
            gson = new Gson();
        }
    }
    private ParseJson() {
    }
    public static List<Storage> parseStorageList(String json) {
        Type type = new TypeToken<List<Storage>>() {
        }.getType();
        return gson.fromJson(json, type);
    }
    public static List<User> parseUser(String json) {
        Type type = new TypeToken<List<User>>() {
        }.getType();
        return gson.fromJson(json, type);
    }
    public static List<ImportItem> parseImportItem(String json) {
        Type type = new TypeToken<List<ImportItem>>() {
        }.getType();
        return gson.fromJson(json, type);
    }
    public static List<ApplicationItem> parseApplicationItem(String json) {
        Type type = new TypeToken<List<ApplicationItem>>() {
        }.getType();
        return gson.fromJson(json, type);
    }
    public static List<ExportItem> parseExportItem(String json) {
        Type type = new TypeToken<List<ExportItem>>() {
        }.getType();
        return gson.fromJson(json, type);
    }
    public static List<Check> parseCheck(String json) {
        Type type = new TypeToken<List<Check>>() {
        }.getType();
        return gson.fromJson(json, type);
    }
    public static List<UseCheck> parseUseCheck(String json) {
        Type type = new TypeToken<List<UseCheck>>() {
        }.getType();
        return gson.fromJson(json, type);
    }
    public static <T> T parseJson(String json, Class<T> clazz) {
        T t = gson.fromJson(json, clazz);
        return t;
    }
}
